$.extend(App,
    {//接口访问
        /**
         * 统一封装的ajax get请求
         * @param url 请求地址
         * @param resolve 请求成功的回掉函数
         * @param reject 请求失败的回掉函数
         */
        get: function (url, resolve, reject, headers) {
			headers = headers || this.headers || (typeof window.top.getHeader == "function" ? window.top.getHeader() : undefined);
            return $.ajax({
                type: "get",
                dataType: "json",
                url: url,
                cache: false,
                headers: headers,
                success: function (result) {
                    if (result && result.success === false && reject) {
						result.obj = result.obj || result.response;
						if(Array.isArray(result.resultWinList) && result.resultWinList.length > 0) {
							App.multipleToastr(result.resultWinList,App.multipleToastrCallBack,App.multipleToastrClosingBack)
						} else {
							reject(result.msg, result.obj);
						}
                    } else {
                        if (resolve) {
                            resolve(result);
                        }
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(jqXHR.responseText);
                    if (401 == jqXHR.status || 403 == jqXHR.status) {
                        window.location.href = "/error/" + jqXHR.status;
                    } else if (reject) {
                        reject(jqXHR.responseText);
                    }
                }
            });
        },
        /**
         * 获取 对象实体
         * @param url
         * @param resolve
         * @param reject
         */
        getEntity: function (url, resolve, reject) {
            return $.ajax({
                type: "get",
                dataType: "json",
                url: url,
                cache: false,
                success: function (result) {
                    resolve(result);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(jqXHR.responseText);
                    if (401 == jqXHR.status || 403 == jqXHR.status) {
                        window.location.href = "/error/" + jqXHR.status;
                    } else if (reject) {
                        reject(jqXHR.responseText);
                    }
                }
            });
        },

        /**
         * 统一封装的ajax post请求
         * @param url 请求地址
         * @param body 请求体
         * @param resolve 请求成功的回掉函数
         * @param reject 请求失败的回掉函数
         */
        post: function (url, body, resolve, reject, multipart, contentType, headers) {
			body = App.delProperty(body,"@type", Infinity);
			headers = headers || this.headers || (typeof window.top.getHeader == "function" ? window.top.getHeader() : undefined);
            var ajaxOption = {
                type: "post",
                dataType: "json",
                url: url,
                data: body,
                cache: false,
                headers: headers,
                processData: !multipart,
                contentType: contentType || (multipart ? false : 'application/x-www-form-urlencoded'),
                success: function (result) {
                    if (result && result.success === false && reject) {
						result.obj = result.obj || result.response;
						if(Array.isArray(result.resultWinList) && result.resultWinList.length > 0) {
							App.multipleToastr(result.resultWinList,App.multipleToastrCallBack,App.multipleToastrClosingBack)
						} else {
							reject(result.msg, result.obj);
						}
                    } else {
                        if (resolve) {
                            resolve(result);
                        }
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(jqXHR.responseText);
                    if (401 == jqXHR.status || 403 == jqXHR.status) {
                        window.location.href = "/error/" + jqXHR.status;
                    } else if (reject) {
                        reject(jqXHR.responseText);
                    }
                }
            };
            return $.ajax(ajaxOption);
        },
        /**
         * 统一封装的ajax post请求
         * @param url 请求地址
         * @param data 请求体
         * @param resolve 请求成功的回掉函数
         * @param reject 请求失败的回掉函数
         */
        postJson: function (url, data, resolve, reject, headers) {
            App.post(url, JSON.stringify(data), resolve, reject, false, "application/json;charset=UTF-8", headers);
        },
        /**
         * 新增修改共用接口
         * @param data 传入数据
         * @param url 接口url
         * @param resolve 请求成功的回掉函数
         * @param reject 请求失败的回掉函数
         * @param isHasList 传入数据是否包含数组 默认为false 代表没有
         * @param headers 请求头
         */
        save: function (data, url, resolve, reject, isHasList, headers) {
            if (!url) {
                url = "save";
            }
            if (isHasList) {
                App.postJson(url, data, resolve, reject, headers)
            } else {
                App.post(url, data, resolve, reject, false, false, headers);
            }

        },
        /**
         * 数据启用
         * @param {rows} 用户选择的数据 
         * @param {*} url  接口地址 默认为相对本页面的enable
         * @param {*} success 成功函数回调
         * @param {*} fail  失败函数回调
         * @returns 
         */
        //启用数据
        enable: function (rows,url,success,fail) {
            if (!rows || rows.length <= 0) {
                $.messager.alert("请选择至少一条数据", "", "error");
                return;
            }
            var mids = "";
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].stateId == 1) {
                    continue;
                }
                mids += rows[i].mid + ",";
            }
            if (mids.length == 0) {
                toastr["error"]("所选择的数据已经是启用状态!", "数据启用失败");
                App.unblockUI();
                return;
            }
            if(!url){
                url="enable";
            }
            $.messager.confirm("数据启用", "请确认是否启用数据？", function (boo) {
                if (boo) {
                    App.blockUI({
                        boxed: true,
                        message: "处理中..."
                    });
                    App.post(url, { mids: mids }, function (result) {
                        App.unblockUI();
                        success(result);
                    }, function (error) {
                        App.unblockUI();
                        fail(error);
                    })
                }
            });
        },
        /**
         * 批量数据禁用接口
         * @param {*} rows 用户选择的数据
         * @param {*} url 接口地址 默认为相对本页面的disable
         * @param {*} success 成功函数回调
         * @param {*} fail 失败函数回调
         * @returns 
         */
        disable: function (rows,url,success,fail) {
            if (!rows || rows.length <= 0) {
                $.messager.alert("请选择至少一条数据", "", "error");
                return;
            }
            var mids = "";
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].stateId == -1) {
                    continue;
                }
                mids += rows[i].mid + ",";
            }
            if (mids.length == 0) {
                toastr["error"]("所选择的数据已经是禁用状态!", "数据禁用失败");
                App.unblockUI();
                return;
            }
            if(!url){
                url="disable";
            }
            $.messager.confirm("数据禁用", "请确认是否禁用数据？", function (boo) {
                if (boo) {
                    App.blockUI({
                        boxed: true,
                        message: "处理中..."
                    });
                    App.post(url, { mids: mids }, function (result) {
                        App.unblockUI();
                        success(result);
                    }, function (error) {
                        App.unblockUI();
                        fail(error);
                    })
                }
            });
        },
        /**
         * 批量新增修改共用接口
         * @param data 传入数据
         * @param url 接口url
         * @param resolve 请求成功的回掉函数
         * @param reject 请求失败的回掉函数
         * @param headers 请求头
         */
        batchSave: function (data, url, resolve, reject, headers) {
            if (!url) {
                url = "batchSave";
            }
            App.postJson(url, data, resolve, reject, headers);
        },
        /**
         * 统一封装的ajax get请求
         * @param url 请求地址
         * @param data 请求体
         * @param resolve 请求成功的回掉函数
         * @param reject 请求失败的回掉函数
         */
        getJson: function (url, resolve, reject, headers) {
            headers = headers || {};
            headers["Content-Type"] = "application/json;charset=UTF-8";
            App.get(url, resolve, reject, headers);
        },
        /**
         * 跳转详情页
         * @param mid
         * @param url
         * @param backUrl
         * @param openModel 1 当前页面打开 2 弹窗打开 3 tab页提交
         * @param callback 弹窗回写
         * @param width 弹窗宽度 默认800
         * @param height 弹窗高度 默认 500
         * @param tabName 标签页名
         */
        detail: function (mid, url, backUrl, openModel, callback, width, height, tabName) {
            if (!openModel) openModel = 1;
            if (openModel == 1) {
                if (url) {
                    location.href = url + (url.indexOf("?") >= 0 ? "&" : "?") + "mid=" + mid + (!backUrl ? '' : '&backUrl=' + encodeURIComponent(backUrl));
                } else {
                    location.href = "detail?mid=" + mid + (!backUrl ? '' : '&backUrl=' + encodeURIComponent(backUrl));
                }
            } else if (openModel == 2) {
                if (url) {
                    url = url + (url.indexOf("?") >= 0 ? "&" : "?") + "mid=" + mid + "&openModel=2";
                } else {
                    url = "detail?mid=" + mid + "&openModel=2";
                }
                if (!width) width = 800;
                if (!height) height = 500;
                $("<div></div>").modalDialog({
                    title: '详情',
                    url: url,
                    width: width,
                    height: height,
                    callBack: callback
                }).click();
            } else if (openModel == 3) {
                if (url) {
                    if(Array.isArray(url)) {
                        url[0] = url[0] + (url[0].indexOf("?") >= 0 ? "&" : "?") + "mid=" + mid + "&openModel=3" + (!backUrl ? '' : '&backUrl=' + encodeURIComponent(backUrl));;
                    } else {
                        url = url + (url.indexOf("?") >= 0 ? "&" : "?") + "mid=" + mid + "&openModel=3" + (!backUrl ? '' : '&backUrl=' + encodeURIComponent(backUrl));;
                    }
                } else {
                    url = "detail?mid=" + mid + "&openModel=3";
                }
                top.window.test.implementRefresh(url, tabName);
            } else {
            }
        },
        /**
         * 跳转到pageoffice详情页
         * @param mid
         * @param url
         * @param width
         * @param height
         */
        poDetail: function (mid, url, width, height) {
            if (url) {
                url = url + (url.indexOf("?") >= 0 ? "&" : "?") + "mid=" + mid;
            } else {
                url = "detail?mid=" + mid;
            }
            if (width || height) {
                var size = 'width=' + width + 'px;height=' + height + 'px;';
            } else {
                var size = 'fullscreen=yes;';
            }
            POBrowser.openWindowModeless(url, size)
        },
        /**
         * 跳转编辑页
         * @param mid
         * @param url
         * @param backUrl
         * @param openModel 1 当前页面打开 2 弹窗打开 3 tab页提交
         * @param callback 弹窗回写
         * @param width 弹窗宽度 默认800
         * @param height 弹窗高度 默认 500
         * @param tabName 标签页名
         */
        edit: function (mid, url, backUrl, openModel, callback, width, height, tabName) {
            if (!openModel) openModel = 1;
            if (openModel == 1) {
                if (url) {
                    location.href = url + (url.indexOf("?") >= 0 ? "&" : "?") + "method=edit&mid=" + mid + (!backUrl ? '' : '&backUrl=' + encodeURIComponent(backUrl));
                } else {
                    location.href = "detail?method=edit&mid=" + mid + (!backUrl ? '' : '&backUrl=' + encodeURIComponent(backUrl));
                }
            } else if (openModel == 2) {
                if (url) {
                    url = url + (url.indexOf("?") >= 0 ? "&" : "?") + "method=edit&openModel=2&mid=" + mid;
                } else {
                    url = "detail?method=edit&openModel=2&mid=" + mid;
                }
                if (!width) width = 800;
                if (!height) height = 500;
                $("<div></div>").modalDialog({
                    title: '编辑',
                    url: url,
                    width: width,
                    height: height,
                    callBack: callback
                }).click();
            } else if (openModel == 3) {
                if (url) {
                    if(Array.isArray(url)) {
                        url[0] = url[0] + (url[0].indexOf("?") >= 0 ? "&" : "?") + "method=edit&openModel=3&mid=" + mid + (!backUrl ? '' : '&backUrl=' + encodeURIComponent(backUrl));;
                    } else {
                        url = url + (url.indexOf("?") >= 0 ? "&" : "?") + "method=edit&openModel=3&mid=" + mid + (!backUrl ? '' : '&backUrl=' + encodeURIComponent(backUrl));;
                    }
                } else {
                    url = "detail?method=edit&openModel=3&mid=" + mid;
                }
                top.window.test.implementRefresh(url, tabName);
            } else {
            }
        },
        /**
         * 跳转pageoffice编辑页
         * @param mid
         * @param url
         * @param width
         * @param height
         */
        poEdit: function (mid, url, width, height) {
            if (url) {
                url = url + (url.indexOf("?") >= 0 ? "&" : "?") + "method=edit&mid=" + mid;
            } else {
                url = "detail?method=edit&mid=" + mid;
            }
            if (width || height) {
                var size = 'width=' + width + 'px;height=' + height + 'px;';
            } else {
                var size = 'fullscreen=yes;';
            }
            POBrowser.openWindowModeless(url, size)
        },
        /**
         * 跳转新增页
         * @param url
         * @param backUrl
         * @param openModel 1 当前页面打开 2 弹窗打开 3 tab页提交
         * @param callback 弹窗回写
         * @param width 弹窗宽度 默认800
         * @param height 弹窗高度 默认 500
         * @param tabName 标签页名
         */
        add: function (url, backUrl, openModel, callback, width, height, tabName) {
            if (!openModel) openModel = 1;
            if (openModel == 1) {
                if (url) {
                    location.href = url + (url.indexOf("?") >= 0 ? "&" : "?") + "method=add" + (!backUrl ? '' : '&backUrl=' + encodeURIComponent(backUrl));
                } else {
                    location.href = "detail?method=add" + (!backUrl ? '' : '&backUrl=' + encodeURIComponent(backUrl));
                }
            } else if (openModel == 2) {
                if (url) {
                    url = url + (url.indexOf("?") >= 0 ? "&" : "?") + "method=add&openModel=2";
                } else {
                    url = "detail?method=add&openModel=2";
                }
                if (!width) width = 800;
                if (!height) height = 500;
                $("<div></div>").modalDialog({
                    title: '新增',
                    url: url,
                    width: width,
                    height: height,
                    callBack: callback
                }).click();
            } else if (openModel == 3) {
                if (url) {
                    if(Array.isArray(url)) {
                        url[0] = url[0] + (url[0].indexOf("?") >= 0 ? "&" : "?") + "method=add&openModel=3" + (!backUrl ? '' : '&backUrl=' + encodeURIComponent(backUrl));;
                    } else {
                        url = url + (url.indexOf("?") >= 0 ? "&" : "?") + "method=add&openModel=3" + (!backUrl ? '' : '&backUrl=' + encodeURIComponent(backUrl));;
                    }
                } else {
                    url = "detail?method=add&openModel=3";
                }
                top.window.test.implementRefresh(url, tabName);
            } else {

            }
        },
        /**
         * 跳转pageoffice新增页
         */
        poAdd: function add(url, width, height) {
            if (url) {
                url = url + (url.indexOf("?") >= 0 ? "&" : "?") + "method=add";
            } else {
                url = "detail?method=add";
            }
            if (width || height) {
                var size = 'width=' + width + 'px;height=' + height + 'px;';
            } else {
                var size = 'fullscreen=yes;';
            }
            POBrowser.openWindowModeless(url, size)
        },
        /**
         * 删除数据
         * @param mid
         * @param url
         * @param callBack
         */
        remove: function (mid, url, callBack, formId, tableId) {
            $.messager.confirm("数据删除警告", "请确认是否删除数据？", function (boo) {
                if (boo) {
                    App.blockUI({
                        boxed: true,
                        message: "处理中..."
                    });
                    url = url ? url + (url.indexOf("?") >= 0 ? "&" : "?") + "mid=" + mid : "delete?mid=" + mid;
                    App.post(url, null, function (result) {
                        App.unblockUI();
                        // $.messager.alert("删除成功", "", "success", function () {
                        //     if (callBack) {
                        //         callBack();
                        //     } else {
                        //         App.search(tableId,formId);
                        //     }
                        // });
						toastr["success"]("删除成功!", "提示");
						if (callBack) {
						    callBack();
						} else {
						    App.search(tableId,formId);
						}
                    }, function (error) {
                        App.unblockUI();
                        // $.messager.alert("删除失败", error, "error");
						toastr["error"](error, "删除失败");
                    });
                }
            });
        },
        /**
         * 多行数据删除
         * @param url 删除url
         * @param isDelBack 是否删除的判断回调方法
         * @param callback 删除成功后的回调方法
         * @param tableId 表格id
         * @param formId 表单Id
         * @param isInv 是否软删除
         */
        batchDelete: function (url, isDelBack, callBack, tableId, formId,isInv) {
            if (!url) {
                url = isInv ? "invalid" : "batchDelete";
            }
            if (!tableId) tableId = "table";
            var rows = $("#" + tableId).datagrid("getChecked");
            if (rows.length > 0) {
                $.messager.confirm("数据删除警告", "请确认是否删除数据？", function (boo) {
                    if (boo) {
                        App.blockUI({
                            boxed: true,
                            message: "处理中..."
                        });
                        var delData = [];
                        for (var i = 0; i < rows.length; i++) {
                            var boo = true;
                            if (isDelBack) {
                                boo = isDelBack(rows[i]);
                            }
                            if (boo !== false) {
                                delData.push(rows[i].mid);
                            }
                        }
                        if (delData.length == 0) {
                            App.unblockUI();
                            // $.messager.alert("提示", "没有一项通过可删除验证！", "warning");
							toastr["warning"]("没有一项通过可删除验证！", "提示");
                            return;
                        }
						App.multipleToastrClosingBack = function(){
                            App.unblockUI();
							if (callBack) {
							    callBack();
							} else {
							    App.search(formId, tableId);
							}
						}
                        App.postJson(url, delData, function (result) {
                            App.unblockUI();
							toastr["success"]("删除成功!", "提示");
							if (callBack) {
							    callBack();
							} else {
							    App.search(formId, tableId);
							}
                        }, function (error) {
                            App.unblockUI();
                            // $.messager.alert("删除失败", error, "error");
							toastr["error"](error, "删除失败");
                        })
                    }
                });
            } else {
                // $.messager.alert("提示", "请至少选择一项数据！", "warning");
				toastr["warning"]("请至少选择一项数据！", "提示");
            }
        },
        /**
         * 提交审批
         * @param tableId
         * @param formId
         * @param url
         * @param isDefVili 是否调用默认的审批提交验证 true:调用 false:不调用
         */
        apply: function (tableId, formId, url, isDefVili) {
            if (!tableId) tableId = "table";
            if (!url) url = "apply";
            var rows = $("#" + tableId).datagrid("getChecked");
            if (rows.length == 1) {
                $.messager.confirm("提示", "请确认是否提交审批数据？", function (boo) {
                    if (boo) {
                        App.blockUI({
                            boxed: true,
                            message: "处理中..."
                        });
                        var row = rows[0];
                        delete row["@type"];
						if(isDefVili && !(row.processStatus === undefined || row.processStatus === null || row.processStatus === "") && rows.processStatus > 0 ) {
							toastr["warning"](row.title + "审批中或已完成审批!", "提示");
							return;
						}
                        App.post(url, row, function (result) {
                            App.unblockUI();
                            // $.messager.alert("提交成功", "", "success", function () {
                            //     App.search(tableId,formId);
                            // });
							toastr["success"]("提交成功!", "提示");
							App.search(tableId,formId);
                        }, function (error) {
                            App.unblockUI();
                            // $.messager.alert("提交失败", error, "error");
							toastr["error"](error, "提交失败");
                        });
                    }
                });
            } else if (rows.length > 1) {
                // $.messager.alert("提示", "只能选择一项数据！", "warning");
				toastr["warning"]("只能选择一项数据!", "提示");
            } else {
                // $.messager.alert("提示", "请选择一项数据！", "warning");
				toastr["warning"]("请选择一项数据!", "提示");
            }
        },
        /**
         * 多行提交审批
         * @param url //提交审批url
         * @param isApplyBack 提交审批前判断回调方法
         * @param tableId
         * @param formId
         * @param isDefVili 是否调用默认的审批提交验证 true:调用 false:不调用
         */
        batchApply: function (url, isApplyBack, tableId, formId, isDefVili) {
            if (!tableId) tableId = "table";
            if (!url) url = "batchApply";
            var rows = $("#" + tableId).datagrid("getChecked");
            if (rows.length > 0) {
                $.messager.confirm("提示", "请确认是否提交审批数据？", function (boo) {
                    if (boo) {
                        App.blockUI({
                            boxed: true,
                            message: "处理中..."
                        });
                        var applyData = [],titles= [];
                        for (var i = 0; i < rows.length; i++) {
                            delete rows[i]["@type"];
                            var boo = true;
							if(isDefVili && !(rows[i].processStatus === undefined || rows[i].processStatus === null || rows[i].processStatus === "") && rows[i].processStatus > 0) boo = false;
                            if (boo && isApplyBack) {
                                boo = isApplyBack(rows[i]);
                            }
                            if (boo !== false) {
                                applyData.push(rows[i]);
                            } else{
								titles.push(rows[i].title)
							}
                        }
                        if (applyData.length == 0) {
                            App.unblockUI();
                            // $.messager.alert("提示", "没有一项通过可提交审批验证！", "warning");
							toastr["warning"]("没有一项通过可提交审批验证!", "提示");
                            return;
       //                  } else if(titles.length) {
							// toastr["warning"]("[" + titles.join("]、[") + "]审批中或已完成审批!", "提示");
						}
						App.multipleToastrClosingBack = function(){
                            App.unblockUI();
							App.search(formId, tableId);
						}
                        App.postJson(url, applyData, function (result) {
                            App.unblockUI();
                            // $.messager.alert("提交成功", "", "success", function () {
                            //     App.search(tableId,formId);
                            // });
							if(result.msg) toastr["error"]((titles.length ? "[" + titles.join("]、[") + "]重复提交!<br/>" : "") + result.msg, "提示");
							else if(titles.length) toastr["error"]("[" + titles.join("]、[") + "]重复提交!", "提示");
							else toastr["success"]("提交审批成功", "提示");
							App.search(tableId,formId);
                        }, function (error) {
                            App.unblockUI();
                            // $.messager.alert("提交失败", error, "error");
							toastr["error"]((titles.length ? "[" + titles.join("]、[") + "]重复提交!<br/>" : "") + error, "提交失败");
                        });
                    }
                });
            } else {
                // $.messager.alert("提示", "请至少选择一项数据！", "warning");
				toastr["warning"]("请至少选择一项数据!", "提示");
            }
        },
        /**
         * 终止流程
         * @param mid
         * @param url
         * @param callBack
         */
        withdraw: function (mid, url, callBack, formId, tableId) {
            $.messager.confirm("终止警告", "请确认是否终止该数据？", function (boo) {
                if (boo) {
                    App.blockUI({
                        boxed: true,
                        message: "处理中..."
                    });
                    url = url ? url + (url.indexOf("?") >= 0 ? "&" : "?") + "mid=" + mid : "withdraw?mid=" + mid;
                    App.post(url, null, function (result) {
                        App.unblockUI();
                        // $.messager.alert("终止成功", "", "success", function () {
                        //     if (callBack) {
                        //         callBack();
                        //     } else {
                        //         App.search(tableId,formId);
                        //     }
                        // });
						toastr["success"]("终止成功!", "提示");
						if (callBack) {
						    callBack();
						} else {
						    App.search(tableId,formId);
						}
                    }, function (error) {
                        App.unblockUI();
                        // $.messager.alert("终止失败", error, "error");
						toastr["error"](error, "提交失败");
                    });
                }
            });
        },
        /**
         * 批量导入
         * @param url
         */
        import: function (url,callback,closing) {
            if (!url) url = "import";
            $("<div></div>").modalDialog({
                title: '导入',
                url: url,
                width: 500,
                height: 225,
                callback: callback,
                closing: closing,
            }).click();
        },
        /**
         * 批量导出台账数据--老版本
         * @param tableId
         * @param url
         */
        exportOld: function (tableId, url) {
            if (!tableId) tableId = "table";
            var rows = $("#" + tableId).datagrid("getChecked");
            if (rows.length == 1) {
                location.href = url ? url + (url.indexOf("?") >= 0 ? "&" : "?") + "mid=" + rows[0].mid : "export?mid=" + rows[0].mid;
            } else if (rows.length > 1) {
                $.messager.alert("只能选择一项数据！", "提示", "warning");
            } else {
                $.messager.alert("请选择一项数据！", "提示", "warning");
            }
        },
        /**
         * 批量导出台账数据
         * @param tableId
         * @param url
         */
        export: function (tableId, formId, url) {
            if (!tableId) tableId = "table";
            if (!formId) formId = "searchForm";
            if (!url) url = "export";
            var data = localStorageManage.get(tableId, formId).queryParams;
            console.log("export data:" + data);
            App.batchExport(url, data);
        },
        /**
         * 导出并下载文件,支持导出多个文件
         * @param url
         * @param data 数据过滤条件
         */
        batchExport: function (url, data) {
            url = url ? url : "batchExport";
            App.blockUI({
                boxed: true,
                message: "处理中..."
            });
            App.post(url, data, function (result) {
                App.unblockUI();
                if (Array.isArray(result.response)) {
                    result.response.forEach(function (downUrl, index) {
                        App.download(downUrl, index);
                    });
                } else {
                    App.download(result.response, 0);
                }
            }, function (error) {
                // $.messager.alert("下载失败", error, "error");
				toastr["error"](error, "下载失败");
                App.unblockUI();
            });
        },
        download: function (url, name) {
            if (!!window.ActiveXObject || 'ActiveXObject' in window) {
                window.open(url, '_blank')
            } else {
                var a = document.createElement("a"), //创建a标签
                    e = document.createEvent("MouseEvents"); //创建鼠标事件对象
                e.initEvent("click", false, false); //初始化事件对象
                a.href = url; //设置下载地址
                a.download = name; // 设置下载文件名
                a.dispatchEvent(e); //给指定的元素，执行事件click事件
            }
        },
        /**
         * 软删除
         * @param mid
         * @param url
         * @param callBack
         */
        invalid: function (mid, url, callBack) {
            var self = this;
            $.messager.confirm(
                "警告",
                "确认删除？",
                function (boo) {
                    if (boo) {
                        App.blockUI({
                            boxed: true,
                            message: "处理中..."
                        });
                        self.post(url ? url + (url.indexOf("?") >= 0 ? "&" : "?") + "mid=" + mid : "invalid?mid=" + mid,
                            null,
                            function (result) {
                                App.unblockUI();
                                // $.messager.alert("删除成功", "", "success", function () {
                                //     if (callBack) {
                                //         callBack();
                                //     } else {
                                //         search();
                                //     }
                                // });
								toastr["success"]('删除成功', "提示");
								if (callBack) {
								    callBack();
								} else {
								    search();
								}
                            }, function (error) {
                                App.unblockUI();
                                // $.messager.alert("删除失败", error, "error");
								toastr["error"](error, "删除失败");
                            });
                    }
                });
        },
        /**
         * 复制
         * @param mid
         * @param url
         * @param callBack
         */
        copy: function (mid, url, callBack) {
            var self = this;
            App.blockUI({
                boxed: true,
                message: "处理中..."
            });
            self.post(url ? url + (url.indexOf("?") >= 0 ? "&" : "?") + "mid=" + mid : "copy?mid=" + mid,
                null,
                function (result) {
                    App.unblockUI();
                    $.messager.alert("复制成功", "", "success", function () {
                        if (callBack) {
                            callBack();
                        } else {
                            App.search();
                        }
                    });
					toastr["success"]('复制成功', "提示");
					if (callBack) {
					    callBack();
					} else {
					    App.search();
					}
                }, function (error) {
                    App.unblockUI();
                    // $.messager.alert("复制失败", error, "error");
					toastr["error"](error, "复制失败");
                });
        },
		
		multipleToastr: function(data,callback,closing){
			$("<div></div>").modalDialog({
			    url: '/static/global/scripts/plugins/multiple-toastr-model.html',
			    width: 800,
			    height: 600,
				params: data,
			    callBack: function(){
					if(callback) callback();
				},
				closing: function(){
					if(closing) closing();
				}
			}).click();
		},
    }, {//常用方法
        /**
         * 获取窗口高度
         * @param window
         * @returns {{winWidth: number, winHeight: number}}
         */
        getWindowSize: function (window) {
            var winWidth;
            var winHeight;
            if(window.innerWidth === 0) {
                var choiceFrame = $("#contentPane .active .content_iframe",top.window.document);
                if(choiceFrame.length > 0){
                    window = choiceFrame[0].contentWindow;
                }
            }
            // 获取窗口宽度
            if (window.innerWidth)
                winWidth = window.innerWidth;
            else if ((document.body) && (document.body.clientWidth))
                winWidth = document.body.clientWidth;
            // 获取窗口高度
            if (window.innerHeight)
                winHeight = window.innerHeight;
            else if ((document.body) && (document.body.clientHeight))
                winHeight = document.body.clientHeight;
            // 通过深入 Document 内部对 body 进行检测，获取窗口大小
            if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
                winHeight = document.documentElement.clientHeight;
                winWidth = document.documentElement.clientWidth;
            }
            return {"winWidth": winWidth, "winHeight": winHeight};
        },
        /**
         * 获取Portlet内部可用高度，适合整个页面只有一个portlet且有portletTitle的高度计算
         * @returns {number}
         */
        getPortletInnerHeight: function () {
            var windowHeight = App.getWindowSize(window).winHeight;
            var portletTitleHeight = 35;
            var portletBodyPaddingHeight = 10;
            var portletPaddingHeight = 15;
            var pageContentPaddingHeight = 20;
            return windowHeight - portletTitleHeight - portletBodyPaddingHeight - portletPaddingHeight - pageContentPaddingHeight;
        },
        //获取URL中的查询参数
        getQueryString: function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return decodeURIComponent(r[2]);
            }
            return null;
        },
        /**
         * easyui弹窗自动创建控件
         * @param element 作用范围
         */
        easyuiParse: function (element) {
            $.parser.parse(element);
        },
        /**
         * 下载文件
         * @param url 下载路径
         * @param fileName 文件名称
         */
        downLoadFile: function (url, fileName) {
            var a = top.document.createElement('a');
            var event = new MouseEvent('click');
            a.download = fileName;
            a.href = url;
            a.dispatchEvent(event);
        },
        /**
         * 单个文件上传数据初始化处理
         * @param {Object} name 存放文件id的name
         * @param {Object} isDynamicForm 判断是否动态表单调用改方法 true为是，false为不是
         */
        fileInit: function (name, isDynamicForm) {
			if(isDynamicForm){
				try {
					return $("#" + name).val() ? JSON.parse($("#" + name).val()) : null;
				} catch(e) {
					return null;
				}
			}
            var data = {},
                fileType = ["fileName", "thumbUrl", "htmlUrl"],
                boo = false;
            for (var i = 0; i < fileType.length; i++) {
                if ($("#" + name + fileType[i]).length > 0) {
                    var textbox = $.data($("#" + name + fileType[i])[0]);
                    if (textbox.textbox) {
                        data[fileType[i]] = $("#" + name + fileType[i]).textbox("getValue");
                    } else {
                        data[fileType[i]] = $("#" + name + fileType[i]).val();
                    }
                    if (data[fileType[i]]) {
                        boo = true;
                    }
                }
            }
            return boo ? data : null;
        },
        /**
         * 单个文件上传回填数据处理
         * @param {Object} name 存放文件id的name
         * @param {Object} data 文件相关数据
         * @param {Object} isDynamicForm 判断是否动态表单调用改方法 true为是，false为不是
         */
        fileDataSet: function (name, data, isDynamicForm) {
			if(isDynamicForm && data) {
				$("#" + name).val(JSON.stringify(data));
				return;
			}
            var fileType = ["fileName", "thumbUrl", "htmlUrl", "fileType"];
            for (var i = 0; i < fileType.length; i++) {
                if ($("#" + name + fileType[i]).length > 0) {
                    var values = '';
                    if(Array.isArray(data)) {
                        var vals = [];
                        for(var j = 0; j < data.length; j++){
                            vals.push(data[j][fileType[i]]);
                        }
                        if(vals.length > 0) values = JSON.stringify(vals);
                    } else if(data){
                        values = data[fileType[i]];
                    }
                    var textbox = $.data($("#" + name + fileType[i])[0]);
                    if (textbox.textbox) {
                        $("#" + name + fileType[i]).textbox("setValue", values);
                    } else {
                        $("#" + name + fileType[i]).val(values);
                    }
                }
            }
        },
        /**
         * 从体系文件里获取模板
         * @param {Object} fileNo 文件编号
         * @param {Object} callback 回调函数
         * @param {Object} width 弹窗宽度
         * @param {Object} height 弹窗高度
		 * @param {effectiveDateEnd}  生效日期，格式为2022-05-21
         * @param {Object} title 弹窗高度
         */
        getTemplate: function (fileNo, callBack, width, height,effectiveDateEnd,title) {
            if (!fileNo) {
                toastr["warning"]("请输入文件编号!", "警告提示");
				App.unblockUI();
                return;
            }
            // 特殊模板编号意味着不需要模板
            if('noTemplateFileNo' !== fileNo){
                var url = "/filesmanage/fileInfo/queryHistoryFileInfo?fileNo=" + fileNo;

                if(effectiveDateEnd){
                  url=url+"&effectiveDateEnd="+effectiveDateEnd;
                }


                App.get(url, function (list) {
                    if (!Array.isArray(list)) {
                        toastr["error"]('请联系管理员', "错误提示");
						App.unblockUI();
                    } else if (list.length > 1) {
                        if (!width) width = 800;
                        if (!height) height = 500;
						if(!title) title = "文件选择器";
                        $("<div></div>").modalDialog({
                            title: title,
                            url: '/filesmanage/fileInfo/choice?excludeBatchFileId=4&fileNo=' + fileNo,
                            width: width,
                            height: height,
                            callBack: function (result) {
                                console.log(result);
                                callBack(result[0].formTemplateId);
                            }
                        }).click();
						App.unblockUI();
                    } else if (list.length > 0) {
                        console.log(list);
                        callBack(list[0].formTemplateId);
                    } else {
                        toastr["error"]("未获取到体系文件模板，请联系体系文件管理员！", "生成失败");
						App.unblockUI();
                    }
                }, function (error) {
                    toastr["error"](error, "错误提示");
					App.unblockUI();
                });
            } else {
                // 特殊的模板编号
                callBack(-1);
            }
        },
		/**
		 * @param {Object} data 数据 可以是数组、对象、JSON字符串
		 * @param {Object} properties 要删除的字段
		 * @param {Object} level 要删到那一层 层级是以对象为标准，数组和JSON字符串进入层级计算，默认为1，Infinity为无限
		 */
		delProperty: function (data,properties,level){
			if(typeof properties === "string") properties = properties.split(",");
			else if(!Array.isArray(properties) || !properties.length) return data;
			if(!level) level = 1;
			function delPropertyByKey(data){
				if(Array.isArray(data)){
					for(var i = 0; i < data.length; i++) {
						data[i] = delPropertyByKey(data[i]);
					}
				} else if(typeof data === "object") {
					if(level !== Infinity) level--;
					for(var key in data) {
						if(properties.indexOf(key) != -1) delete data[key];
						else if(level === Infinity || level > 0) data[key] = delPropertyByKey(data[key]);
					}
				} else if(typeof data === "string" && data.indexOf("{") != -1){
					try{
						data = JSON.parse(data);
						data = JSON.stringify(delPropertyByKey(data));
					} catch(e){}
				}
				return data;
			}
			return delPropertyByKey(data);
		},
		/**
		 * 当人员为单个时，设置人员为该字段默认值
		 * @param {Object} opts 可以是数组也可以是对象，
		 * 以下为opts要传的参数
		 * idField: 存放用户mid的字段的隐藏域id
		 * nameField: 存放用户名称的字段的文本框id
		 * callBack: 要存放用户额外信息时，通过callBack方法写相关代码，callBack方法传出参数为用户信息
		 * filterAll: 查询所有用户，不以当前登录人进行相关过滤
		 * authorize: 批准
		 * roleIds: 角色id
		 * orgId: 住址id
		 * orgLevelCode: 组织levelCode
		 * loginname: 当前用户登录名
		 */
		userSet: function(opts){
			if(opts && Array.isArray(opts)) {
				for(var i = 0; i < opts.length; i++){
					App.userSetByAjax(opts[i]);
				}
			} else if(typeof opts === "object") {
				App.userSetByAjax(opts);
			}
		},
		/**
		 * 当人员为单个时，设置人员为该字段默认值
		 * @param {Object} opt
		 * 以下为opt属性
		 * idField: 存放用户mid的字段的隐藏域id
		 * nameField: 存放用户名称的字段的文本框id
		 * callBack: 要存放用户额外信息时，通过callBack方法写相关代码，callBack方法传出参数为用户信息
		 * filterAll: 查询所有用户，不以当前登录人进行相关过滤
		 * authorize: 批准
		 * roleIds: 角色id
		 * orgId: 住址id
		 * orgLevelCode: 组织levelCode
		 * loginname: 当前用户登录名
		 */
		userSetByAjax: function(opt){
			opt = $.extend(true,{
				idField: "",
				nameField: "",
				callBack: null,
			},opt);
			var urlParams = {
				filterAll: true,
				authorize: false,
				roleIds: null,
				orgId: null,
				orgLevelCode: null,
				loginname: null,
			};
			var urlStr = [];
			for(var key in urlParams) {
				if(opt[key] !== undefined && opt[key] !== null && opt[key] !== "") {
					urlStr.push(key + "=" + opt[key]);
				} else if(urlParams[key] !== undefined && urlParams[key] !== null && urlParams[key] !== "") {
					urlStr.push(key + "=" + urlParams[key]);
				}
			}
			var url = "/rbac/user/dataGrid";
			if(urlStr.length > 0) url += "?" + urlStr.join("&");
			App.get(url,function(res){
				if(res && Array.isArray(res.rows)){
					if(res.rows.length === 1){
						if(opt.idField && !$("#" + opt.idField).val()) $("#" + opt.idField).val(res.rows[0].mid);
						if(opt.nameField && !$("#" + opt.nameField).textbox("getValue")) $("#" + opt.nameField).textbox("setValue",res.rows[0].name);
						if(opt.callBack){
							opt.callBack(res.rows[0]);
						}
					}
				} else {
					toastr["error"]("获取人员信息失败！", "错误提示");
				}
			},function(err){
			    toastr["error"](err, "错误提示");
			})
		},
    }, { //表格通用方法
        _csrf: null,
        editRow: {},//编辑状态的行
        filterRules: {},
        /**
		 * 计算table的高度
		 * @param {Object} containerId 容器Id 用于多个表格在同一页时操作用的
		 * @param {Object} extraHeight 需要额外减去的高度 不能是百分数
		 */
        countHeight: function (containerId, extraHeight) {
			if(containerId) containerId = "#" + containerId + " ";
			else containerId = "";
			if(!extraHeight) extraHeight = 0;
			else extraHeight = parseFloat(extraHeight);
            var bodyHeight = $('body').outerHeight(true) - extraHeight;
            var customTitle = $(containerId + '.custom-title').outerHeight(true);
            if (!customTitle) customTitle = 0;
            var searchHeight = $(containerId + '.list-search').outerHeight(true);
            if (!searchHeight) searchHeight = 0;
            var btnGroupHeight = $(containerId + '.list-btn-row').outerHeight(true);
            if (!btnGroupHeight) btnGroupHeight = 0;
            var formActionPanel = $(containerId + '.form-action-panel').outerHeight(true);
            if (!formActionPanel || $(containerId + '.page-content-form .form-action-panel').length > 0) formActionPanel = 0;
            var tableHeight = bodyHeight - customTitle - searchHeight - btnGroupHeight - formActionPanel - 50;
            $(containerId + '.table-wrapper').css('height', tableHeight);
            return tableHeight;
        },
		/**
		 * 查询部分展开收起
		 * @param {Object} action 操作 fold收起 unfold展开
		 * @param {Object} tableId 表格Id
		 * @param {Object} containerId 容器Id 用于多个表格在同一页时操作用的
		 */
        panelFold: function (action, tableId ,containerId) {
			if(containerId) containerId = "#" + containerId + " ";
			else containerId = ''
            if (!tableId) tableId = 'table';
            if (action == 'fold') {
                $(containerId + '.list-search').animate({'height': $(containerId + '.list-search .col-md-4:first-child').height() + "px"}, 'fast');
                $(containerId + '.panel-fold').css('display', 'none');
                $(containerId + '.panel-unfold').css('display', 'block');
            } else {
                $(containerId + '.list-search').css('height', 'auto');
                $(containerId + '.panel-fold').css('display', 'block');
                $(containerId + '.panel-unfold').css('display', 'none');

            }
            var timeout = setTimeout(function () {
                App.countHeight(containerId);
                $("#" + tableId).datagrid("resize");
                clearTimeout(timeout);
            }, 150)
        },
        //冒泡提示
        publicBubble: function (data, row, index) {
            if (undefined !== data && null !== data) {
                return "<sapn title='" + data + "'>" + data + "</sapn>";
            } else {
                return "";
            }
        },
        /**
         * 表单子表添加
         * @param tableId 子表标签id值
         * @param url 选择弹窗的url
         * @param mapCallBack 字段映射回调方法
         * @param childFromDefineId 当前子表的子表信息表主键值
         * @param width 弹窗宽度
         * @param height 弹窗高度
         */
        sublistAdd: function (tableId, url, mapCallBack, childFromDefineId, width, height,multiSelect) {
            var $this = this,
                length = $("#" + tableId).datagrid("getData").rows.length;
            if (url) {
                if (!width) width = 800;
                if (!height) height = 500;
				if(multiSelect === undefined || multiSelect === null || multiSelect === "") multiSelect = true;
                $("<div></div>").modalDialog({
                    title: '添加数据',
                    url: url,
                    width: width,
                    height: height,
					params: {multiSelect: multiSelect},
                    callBack: function (data,data2) {
                        if (data2) data = data2;
                        var sourceData = [];
                        if (Array.isArray(data)) {
                            sourceData = data;
                        } else if (data) {
                            sourceData.push(data);
                        }
						data = sourceData;
                        if (data && data.length > 0) {
                            for (var i = 0; i < data.length; i++) {
                                var item = data[i], obj;
                                delete item["@type"];
                                if (mapCallBack) {
                                    var mapData = mapCallBack(item, childFromDefineId);
                                    if (mapData) {
                                        obj = $.extend({}, mapData);
                                    }
                                }
                                if (obj) {
                                    $("#" + tableId).datagrid("appendRow", obj);
                                    $("#" + tableId).datagrid("beginEdit", length);
                                    $this.editRow[tableId + '_' + length] = true;
                                    $("#" + tableId).datagrid("selectRow", length);
									length++;
                                }
                            }
                        }
                    }
                }).click();
            } else {
                $("#" + tableId).datagrid("appendRow", mapCallBack ? mapCallBack({}, childFromDefineId) : {});
                $("#" + tableId).datagrid("beginEdit", length);
                this.editRow[tableId + '_' + length] = true;
                $("#" + tableId).datagrid("selectRow", length);
            }
        },
        /**
         * 表单子表编辑
         * @param tableId 子表标签id值
         */
        sublistEdit: function (tableId) {
            var rows = $("#" + tableId).datagrid("getChecked");
            if (rows.length > 0) {
                for (var i = 0; i < rows.length; i++) {
                    var rowIndex = $("#" + tableId).datagrid('getRowIndex', rows[i]);
                    if (!this.editRow[tableId + '_' + rowIndex]) {
                        $("#" + tableId).datagrid("beginEdit", rowIndex);
                        this.editRow[tableId + '_' + rowIndex] = true;
                        $("#" + tableId).datagrid("selectRow", rowIndex);
                    }
                }
            } else {
                $.messager.alert("提示", '请必须选择一项进行编辑', "warning");
            }
        },
        /**
         * 表单子表保存
         * @param tableId 表标签id值
         * @param baseUrl 表数据的添加baseurl
         */
        sublistSave: function (tableId, baseUrl) {
            var rows = $("#" + tableId).datagrid("getChecked");
            if (rows.length > 0) {
                for (var i = 0; i < rows.length; i++) {
                    var rowIndex = $("#" + tableId).datagrid('getRowIndex', rows[i]);
                    if (this.editRow[tableId + '_' + rowIndex]) {
                        $("#" + tableId).datagrid("endEdit", rowIndex);
                        $("#" + tableId).datagrid("beginEdit", rowIndex);
                        this.sublistSaveByAjax(tableId, baseUrl, rowIndex);
                    }
                }
            } else {
                $.messager.alert("提示", '请必须选择一项进行编辑', "warning");
            }
        },
        /**
         * 表单ajax保存
         * @param tableId 子表标签id值
         * @param baseUrl 表数据的添加baseUrl
         * @param rowIndex 当前行号
         */
        sublistSaveByAjax: function (tableId, baseUrl, rowIndex) {
            var data = $("#" + tableId).datagrid("getData"),
                column = $("#" + tableId).datagrid("options").columns[0],
                row = data.rows[rowIndex],
                boo = false,
                $this = this;
            for (var i = 0; i < column.length; i++) {
                if (row[column[i].field]) {
                    boo = true;
                    break;
                }
            }
            if (!boo) {
                toastr["warning"]("请填写第" + (rowIndex + 1) + "行数据", "提示");
                return;
            }
            if (this._csrf) {
                $.extend(row, this._csrf);
            }
            App.post(baseUrl + (row.mid ? "/edit" : "/add"), row, function (result) {
                if (result && result.success) {
                    if ($this.editRow[tableId + '_' + rowIndex]) {
                        delete $this.editRow[tableId + '_' + rowIndex];
                        $("#" + tableId).datagrid("endEdit", rowIndex);
                    }
                    $("#" + tableId).datagrid("updateRow", {
                        index: rowIndex,
                        row: result.response
                    });
                    $("#" + tableId).datagrid("endEdit", rowIndex);
                } else if (result.msg) {
                    toastr["error"](result.msg, "提示", function () {
                    });
                } else {
                    toastr["error"]('子表信息保存失败', "提示", function () {
                    });
                }
            }, function (error) {
                toastr["error"](error, "提示", function () {
                });
            })
        },
        /**
         * 表单子表删除
         * @param tableId 子表标签id值
         * @param baseUrl 表数据的添加baseUrl
         * @param callback 删除成功后回调
         * @param isInv 是否软删除
         */
        sublistDel: function (tableId, baseUrl,callback,isInv) {
            var $this = this;
            var rows = $("#" + tableId).datagrid("getChecked");
			rows = [].concat(rows);
            if (rows.length > 0) {
                $.messager.confirm("数据删除警告", "请确认是否删除数据？", function (result) {
                    if (result) {
                        $this.sublistDelByAjax(tableId, baseUrl, rows,callback,isInv);
                    } else {
                        result = false;
                    }
                    return result;
                });
            } else {
                $.messager.alert("提示", '请必须选择一项进行删除', "warning");
            }
        },

        /**
         * 表单ajax删除
         * @param tableId 子表标签id值
         * @param baseUrl 表数据的添加baseUrl
         * @param delDatas 删除的数据
         * @param callback 删除成功后回调
         * @param isInv 是否软删除
         */
        sublistDelByAjax: function (tableId, baseUrl, delDatas,callback,isInv) {
            var $this = this, data = [];
            for (var i = 0; i < delDatas.length; i++) {
                if (delDatas[i].mid) {
                    data.push(delDatas[i].mid);
                }
            }
            if (data.length > 0) {
                App.postJson(baseUrl + (isInv ? "/invalid" : "/batchDelete"), data, function (result) {
                    if (result && result.success) {
						if(result.obj.length != data.length){
							toastr["error"](result.msg, "提示");
						}
						for(var i = data.length - 1; i >= 0; i--) {
							for(var j = 0; j < result.obj.length; j++){
								if(data[i] == result.obj[j]){
									data.splice(i,1);
									break;
								}
							}
						}
                    } else if (result.msg) {
                        toastr["error"](result.msg, "提示");
                    } else {
                        toastr["error"]('子表信息删除失败', "提示", function () {
                        });
                    }
					for(var i = delDatas.length - 1; i >= 0; i--) {
						for(var j = 0; j < data.length; j++){
							if(delDatas[i].mid == data[j]){
								delDatas.splice(i,1);
								break;
							}
						}
					}
					$this.sublistDelCallback(tableId, delDatas,callback);
                }, function (error) {
                    toastr["error"](error, "提示");
					for(var i = delDatas.length - 1; i >= 0; i--) {
						for(var j = 0; j < data.length; j++){
							if(delDatas[i].mid == data[j]){
								delDatas.splice(i,1);
								break;
							}
						}
					}
					$this.sublistDelCallback(tableId, delDatas,callback);
                }, this._csrf);
            } else {
                this.sublistDelCallback(tableId, delDatas,callback);
            }
        },
        /**
         * 删除后处理
         * @param tableId 子表标签id值
         * @param delDatas 删除的数据
         */
        sublistDelCallback: function (tableId, delDatas,callback) {
            var del_rowIndexs = [];
            for (var i = delDatas.length - 1; i >= 0; i--) {
                var rowIndex = $("#" + tableId).datagrid('getRowIndex', delDatas[i]);
                $("#" + tableId).datagrid('deleteRow', rowIndex);
                if (this.editRow[tableId + '_' + rowIndex]) {
                    delete this.editRow[tableId + '_' + rowIndex];
                    del_rowIndexs.push(rowIndex);
                }
            }
            var editRow = {};
            for (var key in this.editRow) {
                var strs = key.split("_");
                if (strs[0] == tableId) {
                    var rowIndex = parseInt(strs[1]);
                    for (var i = 0; i < del_rowIndexs.length; i++) {
                        if (del_rowIndexs[i] < rowIndex) {
                            rowIndex--;
                        }
                    }
                    editRow[tableId + '_' + rowIndex] = true;
                    // $("#" + tableId).datagrid("endEdit", rowIndex);
                    delete this.editRow[key];
                }
            }
            var data = $("#" + tableId).datagrid("getData").rows;
            // $("#" + tableId).datagrid("loadData", data);
            for (var key in editRow) {
                var strs = key.split("_"), rowIndex = parseInt(strs[1]);
                // $("#" + tableId).datagrid("beginEdit", rowIndex);
                this.editRow[tableId + '_' + rowIndex] = true;
                // $("#" + tableId).datagrid("selectRow", rowIndex);
            }
			if(callback) callback(tableId);
        },
        /**
         * 台账页面设置form表单中模糊查询的规则
         * @param filterRules 规则
         * @param tableId 要更新的表Id
         */
        setFilterRules: function (filterRules, tableId) {
            if (!tableId) tableId = 'table';
            this.filterRules[tableId] = filterRules;
        },

        /**
         * 查询
         * @param tableId 要更新的表Id
         * @param formId 表单名称
         * @param isSetStorage 是否缓存本地缓存中
         */
        search: function (tableId, formId, isSetStorage) {
            if (!formId) formId = 'searchForm';
            if (!tableId) tableId = 'table';
            var searchForm = [];
            if ($("#" + formId).length > 0) {
                searchForm = $('#' + formId).serializeArray();
            }
            var filterRules = this.filterRules[tableId] || [];
            if (filterRules && filterRules.length > 0) {
                for (var i = 0; i < filterRules.length; i++) {
                    for (var j = 0; j < searchForm.length; j++) {
                        if (searchForm[j].name == filterRules[i].field) {
                            if (searchForm[j].value) {
                                filterRules[i].value = searchForm[j].value;
                                $('#' + tableId).datagrid('addFilterRule', filterRules[i]);
                            } else {
                                $('#' + tableId).datagrid('removeFilterRule', filterRules[i].field);
                            }
                            break;
                        }
                    }
                }
            }
            $("#" + tableId).datagrid("doFilter"); //更新表格
            if (isSetStorage !== false) {
                localStorageManage.set(tableId, formId);
            }
        },

        /**
         * 查询输入框重置
         * @param tableId 要更新的表Id
         * @param formId 表单名称
         * @param isSetStorage 是否缓存本地缓存中
         */
        reset: function (tableId, formId, isSetStorage) {
            if (!formId) formId = 'searchForm';
            if (!tableId) tableId = 'table';
            var filterRules = this.filterRules[tableId] || [];
            for (var i = 0; i < filterRules.length; i++) {
                $('#' + tableId).datagrid('removeFilterRule', filterRules[i].field);
            }
            $('#' + tableId).datagrid("removeFilterRule");
            $('#' + tableId).datagrid("doFilter"); //更新表格
            if ($("#" + formId).length > 0) {
                $("#" + formId).form({});
                $("#" + formId).form("clear");
            }
            if (isSetStorage !== false) {
                localStorageManage.set(tableId, formId);
            }
        },
        readonly: false,
        /**
         * 主表弹窗设置
         * @param e 触发点
         * @param url 弹窗url
         * @param map 映射
         * @param fromId 表单的id
         * @param width 弹窗宽度
         * @param height 弹窗高度
         */
        mainModalShow: function (e, url, map, fromId, width, height, multiSelect) {
            if (App.readonly) return;
            if (!fromId) fromId = 'form';
            if (!width) width = 800;
            if (!height) height = 500;
            if (!multiSelect) multiSelect = false;
            if (url) {
                $("<div></div>").modalDialog({
                    title: '添加数据',
                    url: url,
                    width: width,
                    params: {multiSelect: multiSelect},
                    height: height,
                    callBack: function (data, data2) {
                        if (data2) data = data2;
                        var obj = {}, sourceData = [];
                        if (Array.isArray(data)) {
                            sourceData = data;
                        } else if (data) {
                            sourceData.push(data);
                        }
                        if (sourceData.length > 0) {
                            for (var j = 0; j < sourceData.length; j++) {
                                var item = sourceData[j];
                                for (var i = 0; i < map.length; i++) {
                                    if (map[i].sourceField) {
                                        if (j != 0) {
                                            obj[map[i].fieldCode] += ',';
                                        } else {
                                            obj[map[i].fieldCode] = '';
                                        }
                                        obj[map[i].fieldCode] += item[map[i].sourceField];
                                    }
                                }
                            }
                        } else {
                            for (var i = 0; i < map.length; i++) {
                                if (map[i].sourceField) {
                                    obj[map[i].fieldCode] = '';
                                }
                            }
                        }
                        $("#" + fromId).form("load", obj);
                        $("#" + fromId).form("validate");
                    }
                }).click();
            } else {
                $.messager.alert("提示", '没有设置弹窗url', "warning");
            }
        },
        getTableDataAndFileData: function (params, tables,filesName) {
            if (!tables) tables = [];
            if (!filesName) filesName = '_form_file_';
            var dataRows = [];
            for (var i = 0; i < tables.length; i++) {
                var item = tables[i];
                dataRows = $("#" + item.table).datagrid("getRows");
                if (dataRows && dataRows.length > 0) {
                    for (var j = 0; j < dataRows.length; j++) {
                        if ($("#" + item.table).datagrid('validateRow', j)) {
                            $("#" + item.table).datagrid('endEdit', j);
                            $("#" + item.table).datagrid('beginEdit', j);
                        } else {
                            $.messager.alert("错误", '在"' + item.tableName + '"表中，您有信息未填写完善', "error");
                            return false;
                        }
                    }
                    dataRows = $("#" + item.table).datagrid("getRows");
                    dataRows.forEach(function (row) {
                        delete row["@type"];
                    });
                    params[item.tableKey] = JSON.stringify(dataRows);
                }
            }
            if ($("#file_table").length > 0) {
                dataRows = $("#file_table").datagrid("getRows");
                if (dataRows && dataRows.length > 0) {
                    dataRows.forEach(function (row) {
                        delete row["@type"];
                    });
                    params[filesName] = JSON.stringify(dataRows);
                }
            }
            return true;
        }
    },{ 
		/** bs端监听通信
		 * @param {Object} type 通信类型
		 * @param {Object} data 通信数据
		 */
		ipcWatch: function(type,data){
			switch(type){
				case top.window.ipcEnum.FAIL: //下载失败
					App.downloadStatusSet(data.mid,0);
					break;
				case top.window.ipcEnum.CANCEL: //取消下载
					App.downloadStatusSet(data.item.mid,2);
					break;
				case top.window.ipcEnum.SUCCESS: //下载完成
					App.downloadStatusSet(data.mid,3);
					break;
			}
		},
		//bs端附件下载
		/**报告附件下载状态更新
		 * @param {Object} mid 任务下载mid
		 * @param {Object} downloadStatus 下载状态 0 下载失败  1 正在下载  2 取消下载  3 下载完成
		 * @param {Object} resolve 成功后的回调函数
		 * @param {Object} reject 失败后的回调函数
		 */
		downloadStatusSet: function(mid, downloadStatus, resolve, reject){
			if(!mid && !downloadStatus){
				toastr["warning"]("没有相关报告附件下载状态需要更新!", "提示");
				return;
			}
			App.blockUI({
				boxed: true,
				message: "处理中..."
			});
			App.post("/reportmanage/reportFileDownload/save",{
				mid: mid,
				downloadStatus: downloadStatus
			},function(result){
                App.unblockUI();
				if(resolve) resolve(result);
			},function(error){
                App.unblockUI();
				console.log(error);
				toastr["error"]("下载状态更新失败！", "提示");
				if(reject) reject(error);
			});
		},
		/**下载记录生成  
		 * @param {Object} reportAttachmentArrayStr 任务单的mid，台账下载必传，详情下载不传
		 * @param {Object} reportFileDownloadArrayStr 文件下载列表字符串
		 * @param {Object} resolve 成功后的回调函数
		 * @param {Object} reject 失败后的回调函数
		 */
		addDownloadRecord: function(reportAttachmentArrayStr, reportFileDownloadArrayStr, resolve, reject){
			if(!reportAttachmentArrayStr && !reportFileDownloadArrayStr){
				toastr["warning"]("没有相关报告需要下载!", "提示");
				return;
			}
			App.blockUI({
				boxed: true,
				message: "处理中..."
			});
			var data = {};
			if(reportAttachmentArrayStr) data.reportAttachmentArrayStr = reportAttachmentArrayStr;
			if(reportFileDownloadArrayStr) data.reportFileDownloadArrayStr = reportFileDownloadArrayStr;
			App.postJson("/reportmanage/reportTaskDownload/addDownloadRecord",data,function(result){
                App.unblockUI();
				if(result.response && result.response.length){
					toastr["success"]("报告附件下载开始，记录生成成功！", "提示");
					if(top.window.renderIpc) top.window.renderIpc.send(top.window.ipcEnum.DOWNLOAD, result.response);
					if(resolve) resolve(result);
				} else {
					toastr["warning"]("勾选的报告没有能下载的附件！", "提示");
				}
			},function(error){
                App.unblockUI();
				console.log(error);
				toastr["error"]("报告附件下载失败！", "提示");
				if(reject) reject(error);
			});
		},
	}
);
